package com.zl.zlbaseproject.model.net.engine;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 郑磊 on 2018/6/3.
 */

public class GsonHelper {
    private static Gson mGson =new Gson();

    public  static <T>T string2Json(String string,Class<T> clazz){
        return mGson.fromJson(string, clazz);
    }

    public static String json2String(Object value) {
        return mGson.toJson(value);
    }



    /**
     * @param json
     * @param clazz
     * @return
     */
    public static <T> List<T> string2List(String json, Class<T> clazz) {
        ArrayList<T> list = mGson.fromJson(json, new TypeToken<List<T>>(){}.getType());
        return list;
    }

}
